package com.iscas.green.extralindextest.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 简单的Servlet示例
 */
@WebServlet(name = "simpleServlet", urlPatterns = "/servlet/simple")
public class SimpleServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;
    private static final Logger log = LoggerFactory.getLogger(SimpleServlet.class);

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        log.info("SimpleServlet收到GET请求");
        
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().println("<html><body>");
        response.getWriter().println("<h2>SimpleServlet示例</h2>");
        response.getWriter().println("<p>这是一个通过@WebServlet注解注册的Servlet</p>");
        response.getWriter().println("<p>当前时间: " + new java.util.Date() + "</p>");
        response.getWriter().println("</body></html>");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        log.info("SimpleServlet收到POST请求");
        
        String message = request.getParameter("message");
        
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().println("<html><body>");
        response.getWriter().println("<h2>POST请求处理结果</h2>");
        response.getWriter().println("<p>接收到的消息: " + (message != null ? message : "无") + "</p>");
        response.getWriter().println("</body></html>");
    }
} 